package org.mspring.mlog.web.module.web.forums;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.mlog.entity.bbs.Forum;
import org.mspring.mlog.service.bbs.ForumService;
import org.mspring.mlog.service.bbs.TopicService;
import org.mspring.platform.utils.RequestUtils;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 主题操作
 * 
 * @author Gao Youbo
 * @since 2013年8月30日
 */
@Widget
@RequestMapping("/forums/topic")
public class BBS_TopicWidget extends BBS_AbstractWidget {

    @Autowired
    private TopicService topicService;
    @Autowired
    private ForumService forumService;

    /**
     * 帖子页面
     * 
     * @param id
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/{id}")
    public String view(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response, Model model) {
        return "skin:/forums/topic/view";
    }

    /**
     * 发表帖子页面
     * 
     * @param id
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/post")
    public String post(HttpServletRequest request, HttpServletResponse response, Model model) {
        List<Forum> forums = forumService.getAll();
        Long forum = RequestUtils.getRequestParameterAsLong(request, "forum");
        if (forum != null) {
            model.addAttribute("forum", forum);
        }
        model.addAttribute("forums", forums);
        return "skin:/forums/topic/post";
    }

    /**
     * 发表帖子
     * 
     * @param id
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/post/save")
    public String post_save(HttpServletRequest request, HttpServletResponse response, Model model) {
        return null;
    }
}
